#ifndef HISTREAMER_PLUGIN_INTF_DEMUXER_PLUGIN_H
#define HISTREAMER_PLUGIN_INTF_DEMUXER_PLUGIN_H

#include <vector>
#include <memory>
#include "plugin_base.h"
#include "plugin_definition.h"
#include "common/plugin_caps.h"

namespace OHOS {
namespace Multimedia {
namespace Plugin {

struct MediaInfo {
    TagMap general;             ///< General Information
    std::vector<TagMap> tracks; ///< Media tracks
};

struct DataSource {
    virtual ~DataSource() = default;
    virtual Status ReadAt(int64_t offset, std::shared_ptr<Buffer> &buffer, size_t expectedLen) = 0;
    virtual Status GetSize(size_t &size) = 0;
};

struct DemuxerPlugin : public PluginBase {
    virtual Status SetDataSource(const std::shared_ptr<DataSource> &source) = 0;
    virtual Status GetMediaInfo(MediaInfo &mediaInfo) = 0;
    virtual size_t GetTrackCount() = 0;
    virtual Status SelectTrack(int32_t trackId) = 0;
    virtual Status UnselectTrack(int32_t trackId) = 0;
    virtual Status GetSelectedTracks(std::vector<int32_t> &trackIds) = 0;
    virtual Status ReadFrame(Buffer &buffer, int32_t timeOutMs) = 0;
    virtual Status SeekTo(int32_t trackId, int64_t timeStampUs, SeekMode mode) = 0;
};

#define DEMUXER_API_VERSION_MAJOR (1)
#define DEMUXER_API_VERSION_MINOR (0)
#define DEMUXER_API_VERSION MAKE_VERSION(DEMUXER_API_VERSION_MAJOR, DEMUXER_API_VERSION_MINOR)

using DemuxerPluginSnifferFunc = int(*)(const std::string &name, std::shared_ptr<DataSource> dataSource);

struct DemuxerPluginDef : public PluginDefBase {
    std::vector<std::string> extensions; ///< File extensions supported by demuxer
    CapabilitySet inCaps;
    CapabilitySet outCaps;
    PluginCreatorFunc<DemuxerPlugin> creator;
    DemuxerPluginSnifferFunc sniffer;
    DemuxerPluginDef() {
        apiVersion = DEMUXER_API_VERSION;
        pluginType = PluginType::DEMUXER;
    }
};

} // namespace Plugin
} // namespace Multimedia
} // namespace OHOS
#endif
